﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLT_Public;
using System.Data;

namespace QLT_Data
{
   public  class Thuoc_Data
    {
       KetNoiCSDL_Data kn = new KetNoiCSDL_Data();
       public DataTable LayDuLieu()
       {
           return kn.LayDuLieu("Load_tbl_Thuoc");
       }
       public DataTable Load_TimKiem_Thuoc()// dùng để cho sự kiện load của form tìm kiếm
       {
           return kn.LayDuLieu("Load_TimKiem_Thuoc");
       }
       public DataTable Load_Thuoc_BanThuoc()
       {
           return kn.LayDuLieu("Load_Thuoc_BanThuoc");
       }
       public DataTable TimKiem_TenThuoc(Thuoc_Public tenThuoc)
       {
           int n = 1;
           string[] name = new string[n];
           object[]value=new object[n];
           name[0] = "@TenThuoc";
           value[0] = tenThuoc.TenThuoc;
           return kn.LayDuLieu("TimKiem_TenThuoc",name,value,n);
       }
       public DataTable TimKiem_GiaTien(int soDau, int soCuoi)
       {
           int n = 2;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@SoDau";
           value[0] = soDau;
           name[1] = "@SoCuoi";
           value[1] = soCuoi;
           return kn.LayDuLieu("TimKiem_GiaTien", name, value, n);
       }
       public DataTable TimKiem_TenLoaiThuoc(LoaiThuoc_Public tenLoaiThuoc)
       {
           int n = 1;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@TenLoaiThuoc";
           value[0] = tenLoaiThuoc.TenLoaiThuoc;
           return kn.LayDuLieu("TimKiem_TenLoaiThuoc",name,value,n);
       }
       public DataTable TimKiem_TenThuoc_TenLoaiThuoc(Thuoc_Public tenThuoc,LoaiThuoc_Public tenLoaiThuoc)
       {
           int n = 2;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@TenThuoc";
           value[0] = tenThuoc.TenThuoc;
           name[1] = "@TenLoaiThuoc";
           value[1] = tenLoaiThuoc.TenLoaiThuoc;
           return kn.LayDuLieu("TimKiem_TenThuoc_LoaiThuoc", name, value, n);
       }
       public DataTable TimKiem_TenThuoc_GiaTien(Thuoc_Public tenThuoc, int soDau, int soCuoi)
       {
           int n = 3;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@TenThuoc";
           value[0] = tenThuoc.TenThuoc;
           name[1] = "@SoDau";
           value[1] = soDau;
           name[2] = "@SoCuoi";
           value[2] = soCuoi;
           return kn.LayDuLieu("TimKiem_TenThuoc_GiaTien",name,value,n);
       }
       public DataTable TimKiem_LoaiThuoc_GiaTien(LoaiThuoc_Public tenLoaiThuoc, int soDau, int soCuoi)
       {
           int n = 3;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@TenLoaiThuoc";
           value[0] = tenLoaiThuoc.TenLoaiThuoc;
           name[1] = "@SoDau";
           value[1] = soDau;
           name[2] = "@SoCuoi";
           value[2] = soCuoi;
           return kn.LayDuLieu("TimKiem_LoaiThuoc_GiaTien",name,value,n);
       }
       public DataTable TimKiem_TenThuoc_LoaiThuoc_GiaTien(Thuoc_Public tenThuoc,LoaiThuoc_Public tenLoaiThuoc, int soDau, int soCuoi)
       {
           int n = 4;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@TenThuoc";
           value[0] = tenThuoc.TenThuoc;
           name[1] = "@TenLoaiThuoc";
           value[1] = tenLoaiThuoc.TenLoaiThuoc;
           name[2] = "@SoDau";
           value[2] = soDau;
           name[3] = "@SoCuoi";
           value[3] = soCuoi;
           return kn.LayDuLieu("TimKiem_TenThuoc_LoaiThuoc_GiaTien", name, value, n);
       }

       //dùng để load combobox

       public DataTable TaoBang(string sql)
       {
           return kn.taoBang(sql);
       }
       public int Insert_Thuoc(Thuoc_Public tenThuoc, Thuoc_Public tenNCC, Thuoc_Public maLoaiThuoc,Thuoc_Public soLuongTon, Thuoc_Public dVT,Thuoc_Public xuatXu, Thuoc_Public hanDung, Thuoc_Public tacDung, Thuoc_Public giaTien)
       {
           int Nparameter = 9;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@TenThuoc";
           value[0] = tenThuoc.TenThuoc;
           name[1] = "@TenNCC";
           value[1] = tenNCC.TenNCC;
           name[2] = "@MaLoaiThuoc";
           value[2] = maLoaiThuoc.MaLoaiThuoc;
           name[3] = "@SoLuongTon";
           value[3] = soLuongTon.SoLuongTon;
           name[4] = "@DVT";
           value[4] = dVT.DVT;
           name[5] = "@XuatXu";
           value[5] = xuatXu.XuatXu;
           name[6] = "@HanDung";
           value[6] = hanDung.HanDung;
           name[7] = "@TacDung";
           value[7] = tacDung.TacDung;
           name[8] = "@GiaTien";
           value[8] = giaTien.GiaTien;
           return kn.update("insert_Thuoc", name, value, Nparameter);
       }
       public int Update_Thuoc(Thuoc_Public maThuoc, Thuoc_Public tenThuoc, Thuoc_Public tenNCC, Thuoc_Public maLoaiThuoc, Thuoc_Public soLuongTon,Thuoc_Public dVT, Thuoc_Public xuatXu, Thuoc_Public hanDung, Thuoc_Public tacDung, Thuoc_Public giaTien)
       {
           int Nparameter = 10;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaThuoc";
           value[0] = maThuoc.MaThuoc;
           name[1]="@TenThuoc";
           value[1] = tenThuoc.TenThuoc;
           name[2] = "@TenNCC";
           value[2] = tenNCC.TenNCC;
           name[3] = "@MaLoaiThuoc";
           value[3] = maLoaiThuoc.MaLoaiThuoc;
           name[4] = "@SoLuongTon";
           value[4] = soLuongTon.SoLuongTon;
           name[5] = "@DVT";
           value[5] = dVT.DVT;
           name[6] = "@XuatXu";
           value[6] = xuatXu.XuatXu;
           name[7] = "@HanDung";
           value[7] = hanDung.HanDung;
           name[8] = "@TacDung";
           value[8] = tacDung.TacDung;
           name[9] = "@GiaTien";
           value[9] = giaTien.GiaTien;
           return kn.update("update_Thuoc", name, value, Nparameter);
       }
       public int Delete_Thuoc(Thuoc_Public maThuoc)
       {
           int Nparameter = 1;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaThuoc";
           value[0] = maThuoc.MaThuoc;
           return kn.update("delete_Thuoc", name, value, Nparameter);
       }
       public int update_Thuoc_SoLuongTon(Thuoc_Public maThuoc, Thuoc_Public soLuongTon)
       {
           int Nparameter = 2;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaThuoc";
           value[0] = maThuoc.MaThuoc;
           name[1] = "@SoLuongTon";
           value[1] = soLuongTon.SoLuongTon;
           return kn.update("Update_Thuoc_SoLuongTon", name, value, Nparameter);
       }
       public int update_Thuoc_SoLuongBan(Thuoc_Public maThuoc, Thuoc_Public soLuongTon)
       {
           int Nparameter = 2;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaThuoc";
           value[0] = maThuoc.MaThuoc;
           name[1] = "@SoLuongTon";
           value[1] = soLuongTon.SoLuongTon;
           return kn.update("Update_Thuoc_SoluongBan", name, value, Nparameter);
       }
       public DataTable TimKiem_Thuoc_BanThuoc(Thuoc_Public tenthuoc)
       {
           int Nparameter = 1;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@TenThuoc";
           value[0] = tenthuoc.TenThuoc;
           return kn.LayDuLieu("TimKiem_Thuoc_BanThuoc", name, value, Nparameter);
       }
    }
}
